package com.zhihaoliang.coroutine.buss.flow

import com.zhihaoliang.coroutine.buss.flow.func.*
import com.zhihaoliang.coroutine.common.list.ListActivity
import com.zhihaoliang.coroutine.common.list.ListItem

/**
 * @author 支豪亮
 * @date 2022/10/24 09:26
 * @des 流的介绍
 */
class FlowActivity : ListActivity() {
    override val listItem: List<ListItem> = listOf(
        ListItem("Flows 简介", 0),
        ListItem("Flows are cold", 1),
        ListItem("Flows Timeout", 2),
        ListItem("Flows Timeout Or Null", 3),
        ListItem("Flow builders : flowOf and asFlow", 4),
        ListItem("Flow operators", 5),
        ListItem("Flow  reduce and fold", 6),
        ListItem("Flows are sequential", 7),
        ListItem("Flow context Thread", 8),
        ListItem("耗时操作的线程切换", 9),
        ListItem("Flow Buffer", 10),
        ListItem("Composing multiple flows : zip vs Combine", 11),
        ListItem("Flattening flows flatMapConcat", 12),
        ListItem("Flattening flows flatMapMerge", 13),
        ListItem("Flattening flows flatMapLatest", 14),
        ListItem("Declarative handling", 15),
        ListItem("Launching flow collect", 16),
        ListItem("Launching flow launchIn", 17),
        ListItem("asFlow can not cancel", 18),
        ListItem("flow {} can cancle", 19),
        ListItem("use cancellable  ", 20),
        ListItem("use ensureActive", 21),
    )


    override fun onItemClick(item: ListItem) {
        when (item.index) {
            1 -> FlowCold.onFlowCold(mainScope)
            2 -> FlowTimeout.onFlowTimeout(mainScope)
            3 -> FlowTimeout.onTimeoutOrNull(mainScope)
            4 -> FlowBuilder.onFlowBuilder(mainScope)
            5 -> FlowOperators.onTransform(mainScope)
            6 -> FlowOperators.onReduce(mainScope)
            7 -> FlowSequential.onSequential(mainScope)
            8 -> FlowThread.onThread(mainScope)
            9 -> FlowThreadSwitch.onThreadSwitch(mainScope)
            10 -> FlowBuffer.onBuffer(mainScope)
            11 -> FlowCompose.onCompose(mainScope)
            12 -> FlowFlatten.onFlatMapConcat(mainScope)
            13 -> FlowFlatten.onFlatMapMerge(mainScope)
            14 -> FlowFlatten.onFlatMapLatest(mainScope)
            15 -> FlowDeclarative.onDeclarative(mainScope)
            16 -> FlowLaunch.onCollect(mainScope)
            17 -> FlowLaunch.onLaunchIn(mainScope)
            18 -> FlowCancel.onAsFlow(mainScope)
            19 -> FlowCancel.onFlow(mainScope)
            20 -> FlowCancel.onCancel(mainScope)
            21 -> FlowCancel.onEnsureActive(mainScope)
            else -> FlowIntroduce.onIntroduce(mainScope)
        }
    }


}